package com.wf.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wf.bean.UserWf;
import com.wf.mapper.UserWfMapperMsp;
import com.wf.service.UserWfMapperMspService;
import com.wf.service.UserWfMapperService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


//@CrossOrigin
@RestController
public class UserWfControllerMps {

    @Autowired
    UserWfMapperMspService userWfMapperMspService;

    // mybatis-plus测试

    // 查一个
    @RequestMapping("/getByIdmps")
    public  UserWf searchOneUser(@RequestParam("id") Integer id){
        // 调什么方法去service 里面查询
        return userWfMapperMspService.getById(id);

    }
    //  查个数
    @RequestMapping("/getAll")
    public long getAllUser(){
        return userWfMapperMspService.count();
    }

    //deleteOneByIdmps
    @RequestMapping("/deleteByIdmps")
    public boolean deleteOneUser(@RequestParam("id") Integer id){
        return userWfMapperMspService.removeById(id);
    }


    // mps 分页查询

    @RequestMapping(value = "/getPageListmsp")
    public Map<String,Object> getPageListmsp(@RequestParam("pageNum") int pageNum,@RequestParam("pageSize") int pageSize,@RequestParam(value = "wfname",required = false) String wfname,@RequestParam(value = "wfage",required = false) Integer wfage){

        Map<String,Object> map = new HashMap<>();
        IPage<UserWf> page = new Page<>(pageNum,pageSize);
        QueryWrapper<UserWf> objectQueryWrapper = new QueryWrapper<>();

        objectQueryWrapper.like("wfname",wfname);// 模糊条件 查询
//        objectQueryWrapper.eq("wfname",wfname);// 等值条件查询
//        objectQueryWrapper.eq("wfage",wfage);// 等值条件查询 两个条件会自己拼接
        // objectQueryWrapper.().().between("age",10,50) 链式调用也可
        IPage<UserWf> wfpage = userWfMapperMspService.page(page, objectQueryWrapper);
      
        // long count = userWfMapperMspService.count();不用自己查个数了

        map.put("list",wfpage);
        //map.put("total",count); // 不用自己查个数了
        return map;


    }

    // mybatis-plus批量删除
    @PostMapping("/deletebatch")
    public boolean deletebatch(@RequestBody List<Long> ids){
        System.out.println("ids"+ids);
       return userWfMapperMspService.removeByIds(ids);
    }


}